﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Photon.SocketServer;
using Common;
using Common.Tools;
using Common.Model;

using MyGameServer.Manager;
using MyGameServer.Model;
using System.IO;
using System.Xml.Serialization;

namespace MyGameServer.Handler
{
    class CreateRoomHandler : BaseHandler
    {
        public CreateRoomHandler()
        {
            OpCode = OperationCode.CreateRoom;
        }
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer)
        {
            Room room = new Room();
            room.roomId = 100000 + MyGameServer.Instance.roomList.Count + 1;
            MyGameServer.Instance.roomList.Add(room);

            CommonUser user = Functions.GetCommonUser(MyGameServer.Instance.onlineUserList, peer.uuid);
            room.playerList.Add(user);

            OperationResponse response = new OperationResponse(operationRequest.OperationCode);

            Dictionary<byte, object> data = new Dictionary<byte, object>();
            data.Add((byte)ParameterCode.CreateRoom, room.roomId);
            response.Parameters = data;
            peer.SendOperationResponse(response, sendParameters);
        }
    }
}
